package cn.hh.wechatkit.pojo.token;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Created by HMH on 2017/3/23.
 * 微信开发的基础AccessToken
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class WxToken_AccessToken {
    //基础的令牌
    private String access_token;
    //有效时常，单位为秒
    private long expires_in;
    //过期时间
    private long expires_time;
    //错误代码
    private String errcode;
    //错误信息
    private String errmsg;


    public WxToken_AccessToken(String access_token, String expires_in, String expires_time) {
        this.access_token = access_token;
        this.expires_in = Long.parseLong(expires_in);
        this.expires_time = Long.parseLong(expires_time);
    }

    public WxToken_AccessToken(String access_token, long expires_in, long expires_time) {
        this.access_token = access_token;
        this.expires_in = expires_in;
        this.expires_time = expires_time;
    }

    public void setExpires_in(long expires_in) {
        this.expires_in = expires_in;
    }

    public Boolean hasError() {
        return errcode!=null && !"0".equals(errcode);
    }

    public boolean isExpired() {
        return expires_time < System.currentTimeMillis();
    }
}
